// DriveNotes. Copyright (c) 2011, Andrei Senchuk. All rights reserved.
package net.taviscaron.drivenotes.web.converter;

import java.util.Map;
import net.taviscaron.drivenotes.shared.model.entity.Charging;
import net.taviscaron.drivenotes.web.util.ParamUtils;

/**
 * Charging converter
 * @author taviscaron
 */
public class ChargingConverter extends FormConverter<Charging> {

    @Override
    public Charging convert(Map params, String prefix) throws InvalidFormException {
        try {
            Charging charging = new Charging();
            charging.setId(ParamUtils.parseLongParam(params, "id", prefix));
            charging.setOdometrValue(ParamUtils.parseIntParam(params, "odometrValue", prefix));
            charging.setPrice(ParamUtils.parseFloatParam(params, "price", prefix));
            charging.setVolume(ParamUtils.parseFloatParam(params, "volume", prefix));
            charging.setFillingStation(ParamUtils.parseStringParam(params, "fillingStation", prefix));
            return charging;
        } catch (IllegalArgumentException e) {
            throw new InvalidFormException();
        }
    }
}
